package com.lb.jwitter.action;


import java.util.ArrayList; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import java.util.Map; 
import com.opensymphony.xwork2.ActionContext; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXADonXinGiaHanHocPhi;
import com.lb.jwitter.service.TblQLDTTXADonXinGiaHanHocPhiService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXADonXinGiaHanHocPhiSearchAction{
    private int pageSize; 
    public void setPageSize(int pageSize) {
       this.pageSize = pageSize;
     }

    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public void setPage(int page) { this.page = page;   }

    public int getPage() {
       return page;
   }

    private int pages; 
    public void setPages(int pages) { this.pages = pages;   }

    public int getPages() {
       return pages;
     }

    private String dataString; 
    public void setDataString(String dataString) { this.dataString = dataString;    }

    public String getDataString() {
       return dataString;
    }

    private Message msg; 
    public Message getMsg() { return msg; }

    private int hocVienId; 
    public void setHocVienId(int hocVienId) {
       this.hocVienId = hocVienId;
  }

    public int getHocVienId() {
       return hocVienId;
  }

    private String mSHV;

    private String tungayNop;
    private String denngayNop;
    private int tuHocKyId; 
    public void setTuHocKyId(int tuHocKyId) {
       this.tuHocKyId = tuHocKyId;
  }

    public int getTuHocKyId() {
       return tuHocKyId;
  }

    private int sangHocKyId; 
    public void setSangHocKyId(int sangHocKyId) {
       this.sangHocKyId = sangHocKyId;
  }

    public int getSangHocKyId() {
       return sangHocKyId;
  }

    private boolean trangThai; 
    private Boolean duyet;

    private List<TblQLDTTXADonXinGiaHanHocPhi> tblQLDTTXADonXinGiaHanHocPhis; 
    public List<TblQLDTTXADonXinGiaHanHocPhi>  getTblQLDTTXADonXinGiaHanHocPhis() {
        return tblQLDTTXADonXinGiaHanHocPhis; 
      } 

    private TblQLDTTXADonXinGiaHanHocPhiService tblQLDTTXADonXinGiaHanHocPhiService; 

	private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_DonXinGiaHanHocPhi", "xem")){ 
        return "noprivilege"; 
    } 
 
        tblQLDTTXADonXinGiaHanHocPhiService = (TblQLDTTXADonXinGiaHanHocPhiService) context.getBean("tbl_QLDTTXA_DonXinGiaHanHocPhiClient"); 
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
        if(mSHV != null && !mSHV.equalsIgnoreCase("")){ 
            ConditionReport con = new ConditionReport(); 
            con.setCol("hocVienId.MSHV");
            con.setValue1("%" + mSHV + "%");
            con.setOperator("like");
            cons.add(con);	
        } 

        if( tungayNop != null && !tungayNop.equalsIgnoreCase("") ){ 
            ConditionReport con = new ConditionReport(); 
            con.setType("date"); 
             con.setCol("ngayNop");
            con.setValue1(tungayNop);
            if (denngayNop != null && !denngayNop.equalsIgnoreCase("") ){ 
                con.setValue2(denngayNop); 
                con.setOperator("between"); 
            } 
            else{ 
                con.setOperator("ge"); 
            } 
            cons.add(con);	
        } 
            else if (denngayNop != null && !denngayNop.equalsIgnoreCase("") ){ 
            ConditionReport con = new ConditionReport(); 
            con.setType("date"); 
             con.setCol("ngayNop");
            con.setValue1(denngayNop);
            con.setOperator("le");
            cons.add(con);	
        }
        
    if(tuHocKyId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("tuHocKyId.id");
        con.setValue1(new Long(tuHocKyId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(sangHocKyId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("sangHocKyId.id");
        con.setValue1(new Long(sangHocKyId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    
    if(true){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("trangThai");
        con.setValue1(trangThai);
        con.setOperator("eq");
        cons.add(con);	
    }
    if(duyet != null){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("duyet");
        con.setValue1(duyet);
        con.setOperator("eq");
        cons.add(con);	
    }
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSize == 0){ 
               pageSize = 20; 
           } 
            if(page == 0){ 
               page =1; 
           } 
           tblQLDTTXADonXinGiaHanHocPhis = tblQLDTTXADonXinGiaHanHocPhiService.findtblQLDTTXADonXinGiaHanHocPhiByCondition(cons,pageSize,page); 
           pages = tblQLDTTXADonXinGiaHanHocPhiService.counttblQLDTTXADonXinGiaHanHocPhiByCondition(cons)/pageSize + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataString = ""; 
      dataString += "&hocVienId=" + hocVienId; 
      dataString += "&tuHocKyId=" + tuHocKyId; 
      dataString += "&sangHocKyId=" + sangHocKyId; 
      dataString += "&trangThai=" + trangThai; 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_QLDTTXA_DonXinGiaHanHocPhi Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 }

public boolean isTrangThai() {
	return trangThai;
}

public void setTrangThai(boolean trangThai) {
	this.trangThai = trangThai;
}

public String getMSHV() {
	return mSHV;
}

public void setMSHV(String mshv) {
	mSHV = mshv;
}

public String getDenngayNop() {
	return denngayNop;
}

public void setDenngayNop(String denngayNop) {
	this.denngayNop = denngayNop;
}

public String getTungayNop() {
	return tungayNop;
}

public void setTungayNop(String tungayNop) {
	this.tungayNop = tungayNop;
}

public Boolean getDuyet() {
	return duyet;
}

public void setDuyet(Boolean duyet) {
	this.duyet = duyet;
}


 } 
 
